package com.duoshu.grj.sosoliuda;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.aliyun.demo.recorder.AliyunSVideoGlSurfaceView;
import com.aliyun.demo.recorder.AliyunVideoRecorder;
import com.aliyun.quview.RecordTimelineView;
import com.aliyun.struct.snap.AliyunSnapVideoParam;
import com.duoshu.grj.sosoliuda.snapvideo.R;

public class SosoRecordActivity extends AliyunVideoRecorder {

    private AliyunSVideoGlSurfaceView mPreview;
    private RecordTimelineView mTimeLine;
    private FrameLayout mRecordLayout;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);

        mPreview = (AliyunSVideoGlSurfaceView)this.findViewById(R.id.aliyun_preview);
        mTimeLine = (RecordTimelineView)this.findViewById(R.id.aliyun_record_timeline);
        mRecordLayout = (FrameLayout) findViewById(R.id.aliyun_record_layout);

        RelativeLayout.LayoutParams preViewParams =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.MATCH_PARENT,
                        RelativeLayout.LayoutParams.MATCH_PARENT);
        preViewParams.addRule(RelativeLayout.ABOVE, 0);
        mPreview.setLayoutParams(preViewParams);

        Resources r = getResources();
        int px = (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());

        RelativeLayout.LayoutParams timeLineViewParams =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.MATCH_PARENT,
                        px);
        timeLineViewParams.addRule(RelativeLayout.BELOW, 0);
        timeLineViewParams.addRule(RelativeLayout.ABOVE, mRecordLayout.getId());
        mTimeLine.setLayoutParams(timeLineViewParams);



    }

    public static void startRecordForResult(Activity activity, int requestCode, AliyunSnapVideoParam param) {
        Intent var3 = new Intent(activity, SosoRecordActivity.class);
        var3.putExtra("video_resolution", param.getResolutionMode());
        var3.putExtra("video_ratio", param.getRatioMode());
        var3.putExtra("record_mode", param.getRecordMode());
        var3.putExtra("filter_list", param.getFilterList());
        var3.putExtra("beauty_level", param.getBeautyLevel());
        var3.putExtra("beauty_status", param.getBeautyStatus());
        var3.putExtra("camera_type", param.getCameraType());
        var3.putExtra("falsh_type", param.getFlashType());
        var3.putExtra("need_clip", param.isNeedClip());
        var3.putExtra("max_duration", param.getMaxDuration());
        var3.putExtra("min_duration", param.getMinDuration());
        var3.putExtra("video_quality", param.getVideoQuality());
        var3.putExtra("video_gop", param.getGop());
        var3.putExtra("video_bitrate", param.getVideoBitrate());
        var3.putExtra("sort_mode", param.getSortMode());
        var3.putExtra("video_framerate", param.getFrameRate());
        var3.putExtra("crop_mode", param.getScaleMode());
        var3.putExtra("min_crop_duration", param.getMinCropDuration());
        var3.putExtra("min_video_duration", param.getMinVideoDuration());
        var3.putExtra("max_video_duration", param.getMaxVideoDuration());
        var3.putExtra("sort_mode", param.getSortMode());
        activity.startActivityForResult(var3, requestCode);
    }
}
